package com.kt.coroutinedemo.Netty

import java.util.Queue
import java.util.concurrent.LinkedBlockingQueue

/**
 * @Author Xzh
 * @Date 2025/8/29
 * @Description
 */
object FileDownloadHelper {

    //下载队列
    val downloadQueue = LinkedBlockingQueue<String>()

    /**
     * 添加下载队列
     */
    fun addDownloadQueue(fileName: String) {
        downloadQueue.add(fileName)
    }

    /**
     * 递归下载队列
     */
   fun startDownloadQueue() {
        if (downloadQueue.isEmpty()) {
            return
        }
        val fileName = downloadQueue.poll()
        NettyClient.downLoadLine(fileName, NettyClient.channel!!.id(), object : DownloadFileListener {
            override fun downloadComplete(filePath: String) {
                startDownloadQueue()
            }

            override fun downloadFailed(msg: String) {
                startDownloadQueue()
            }

            override fun downloadProcess(current: Int, total: Int) {
            }
        })
   }
}